﻿@model MvcCmsOptIn.Models.OptInModel          
@section HtmlHead{
    <link href="@Url.Content("/RazorThemes/" + Model._Portal.SkinName + "/css/optin.css")" rel="stylesheet" type="text/css" />
}
<div class="contentpage-outerdiv">
    <div id="container">
        <div class="breadcrumb">
            <span><a href="/optin-manager">Main Menu</a></span><span>» </span><span><a href="/optin-manager/subscribers">
                Subscribers</a></span><span>» </span><span>Edit</span>
        </div>
        <div style="color: Red;">@ViewBag.Message &nbsp;</div>
        <div id="content">
            <h2>
                Edit Subscriber</h2>
            <form id="form1" action="" method="post">
            <table cellspacing="0" border="0" style="border-collapse: collapse;">
                <tbody>
                    <tr>
                        <td>
                            <table width="600" cellspacing="0" cellpadding="5" border="0" class="frame">
                                <tbody>
                                    <tr>
                                        <td colspan="2" class="toolbar">
                                            <a href="javascript:void(0);" onclick="SaveSubscriber();">                                            
                                                <img border="0" src="/areas/mvccmsoptin/content/buttons/save.gif" id="update" name="update">
                                            </a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            <table width="600" cellspacing="0" cellpadding="5" border="0" class="frame">
                                <tr>
                                    <td colspan="2">
                                        <dl>
                                            <dt>Name </dt>
                                            <dd>
                                                <input type="text" style="width: 90%;" class="required" id="Name" value="@Model._Subscriber.Name" name="Name">
                                            </dd>
                                        </dl>                                    
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <dl>
                                            <dt>EMail</dt>
                                            <dd>
                                                @Html.TextBox("EMail", Model._Subscriber.EMail)
                                            </dd>
                                            <dt>Format</dt>
                                            <dd>
                                                @Html.TextBox("Format", Model._Subscriber.Format)
                                            </dd>
                                        </dl>                                        
                                    </td>
                                    <td align="right">                                        
                                            <dl>
                                            <dt>Do Not Contact</dt>
                                            <dd>
                                                @Html.CheckBox("DoNotContact", Model._Subscriber.DoNotContact)</dt>                                           
                                           </dd>
                                            <dt>Date Created </dt>
                                            <dd>
                                                @Model._Subscriber.CreateDate 
                                            </dd>
                                        </dl>                                    
                                    </td>
                                </tr>
                            </table>
                            <table width="600" cellspacing="0" cellpadding="5" border="0">
                                <tr valign="top">
                                    <td class="formtitle">
                                        <span id="lblRecipients">Lists</span>
                                    </td>
                                    <td class="formdata">
                                        <table style="width: 400px; font-size: 9px;">
                                            <tbody>
                                                <tr>
                                                    <td style="text-align: left; padding-left: 20px; width: 50%;">
                                                        &nbsp;
                                                    </td>
                                                    <td style="text-align: left; padding-left: 40px; width: 50%; font-weight: bold;">
                                                        Belongs to
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                        <span style="display: inline-block; width: 400px;" id="lstRecipients">
                                            <table border="0" style="vertical-align: middle;">
                                                <tbody>
                                                    <tr>
                                                        <td valign="top">
                                                        </td>
                                                        <td align="center" rowspan="2">                                                
                                                            <select class="recipients_select" id="availableLists" multiple="multiple" name="availableLists" size="4">
                                                            @if (Model._Lists != null)
                                                            {
                                                                foreach (var list in Model._Lists)
                                                                {                                                        
                                                                <option value="@list.ListID">@list.ListName</option>
                                                                }
                                                            }
                                                            else
                                                            {
                                                               <option>No Lists!!</option>
                                                               <option>Make Some Now!!</option>
                                                            }
                                                            </select>
                                                        </td>
                                                        <td width="100px" align="center" rowspan="2">
                                                            <input type="button" id="toRight" value="&gt;&gt;"><br>
                                                            <input type="button" id="toLeft" value="&lt;&lt;">
                                                        </td>
                                                        <td align="center" rowspan="2">
                                                            <select class="recipients_select" multiple="multiple" id="currentLists" name="currentLists" size="4">
                                                            @if (Model._AssignedLists != null)
                                                            {
                                                                foreach (var list in Model._AssignedLists)
                                                                {
                                                                <option value="@list.ListID">@list.ListName</option>
                                                                }
                                                            }
                                                            </select>                                                
                                                        </td>
                                                        <td valign="top">
                                                            <img src="/content/images/busy.gif" style="display:none;" id="savingList" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td valign="bottom">
                                                        </td>
                                                        <td valign="bottom">
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </span>
                                    </td>
                                </tr>                            
                            
                            </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            @Html.Hidden("SubscriberID", Model._Subscriber.SubscriberID)
            </form>
        </div>
    </div>
</div>
@Html.Hidden("SubscriberID", @Model._Subscriber.SubscriberID)
@section ScriptContent{
    <script src="@Url.Content("/areas/mvccmsoptin/Scripts/jquery.validate.js")" type="text/javascript"></script>
    <script type="text/javascript">
        function SaveSubscriber() {
            $("#form1").submit();
        }
        function DeleteSubscriber() {
            $("#form1").attr("action", "deletesubscriber");
            $("#form1").submit();
        }
        $("#form1").validate();

    </script>
    <script id="Add/Remove List(s)" type="text/javascript">
        $(document).ready(function () {
            var suppliedSelect = jQuery('#availableLists');
            jQuery('#toRight').click(function () {
                suppliedSelect.find(':selected').each(function (index, elem) {
                    var selectElem = $(elem);
                    if (selectElem.val()) {
                        AddList(selectElem.val());
                        selectElem.appendTo('#currentLists');
                    }
                });
            });
        });
        $(document).ready(function () {
            var suppliedSelect = jQuery('#currentLists');
            jQuery('#toLeft').click(function () {
                suppliedSelect.find(':selected').each(function (index, elem) {
                    var selectElem = $(elem);
                    if (selectElem.val()) {
                        RemoveList(selectElem.val());
                        selectElem.appendTo('#availableLists');
                    }
                });
            });
        });
    </script>
    <script id="Add/RemoveList" type="text/javascript">
        function RemoveList(listId) {
            $("#savingList").show();
            $.post("/optinajax/removelistfromsubscriber/",
		    { SubscriberID: $('#SubscriberID').val(), ListID: listId },
            function (data) {
                if (data.error) {
                    alert(data.error);
                }
                $("#savingList").hide();
            }, "json");
        }
        function AddList(listId) {
            $("#savingList").show();
            $.post("/optinajax/addlisttosubscriber/",
		    { SubscriberID: $('#SubscriberID').val(), ListID: listId, Confirmed: true, useHTML: true },
            function (data) {
                if (data.error) {
                    alert(data.error);
                }
                $("#savingList").hide();
            }, "json");
        }    
    </script>
}
